cmake_minimum_required(VERSION 3.0.0)

set(pro_name curl_http)

project(${pro_name} C CXX)

# find_package(CURL MODULE)
# if(CURL_FOUND)
#     message(STATUS "CURL_INCLUDE_DIRS:${CURL_INCLUDE_DIRS},${CURL_INCLUDES},${CURL_INCLUDE_DIR}")
#     message(STATUS "CURL_LIB_VERSION:${CURL_VERSION_STRING}")
# else(CURL_FOUND)
#     message(FATAL_ERROR ”CURL library not found”)
#     message(ERROR "Please set CURL_DIR or use -D CURL_DIR=${dir} command line params")
# endif()

# find_package not find the curl library when I build the curl from source and not install the system directory
# so use the find_library
find_library(CURL_LIBRARYS NAMES curl HINTS ${CURL_DIR})
message(STATUS "CURL_LIBS:${CURL_LIBS},${CURL_LIBRARYS},${CURL_LIBRARY}")
if(CURL_LIBRARYS)
    message(STATUS "CURL LIBRARY find:${CURL_LIBRARYS}")
    set(CURL_INCLUDES ${CURL_DIR}/../include)
else(CURL_LIBRARYS)
    message(FATAL_ERROR "CURL library not found! Please specified the curl library contented directory,example: -D CURL_DIR=/home/bm/curl/lib")
endif()

# if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch")
#     set(CURL_INCLUDE /home/tools/dev_env/libcurl/include)
#     set(CURL_LIBDIR /home/tools/dev_env/libcurl/lib)
# else()
#     set(CURL_INCLUDE /home/tools/dev_env/libcurl/include)
#     set(CURL_LIBDIR "/usr/local/lib" "/usr/local/lib64")
# endif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch")

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
    message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

add_library(${pro_name} STATIC curl_http.cpp)
# target_link_directories(${pro_name} PUBLIC ${CURL_LIBDIR})
target_link_libraries(${pro_name} PUBLIC ${CURL_LIBRARYS})
target_include_directories(${pro_name} PUBLIC ${CURL_INCLUDES})

# if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch")
# target_include_directories(${pro_name} PUBLIC ${CURL_INCLUDE})
# endif()

set(unit_test http_unit_test)
add_executable(${unit_test} unit_test.cpp)
# target_link_directories(${unit_test} PUBLIC ${CURL_LIBDIR})
target_include_directories(${unit_test} PUBLIC ${CURL_INCLUDES})
target_link_libraries(${unit_test} PUBLIC curl_http ${CURL_LIBRARIES})